<?php

namespace app\admin\model\vppz;

use think\Model;
use traits\model\SoftDelete;

class Community extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'vppz_community';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
		'cover_image'	// 需在此处追加属性，才会触发获取器 getPicImageUrlAttr
    ];

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }


    public function area()
    {
        return $this->belongsTo('Area', 'area_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
	// 获取器直接转换url
	public function getCoverImageAttr($value,$data)
    {
        return \addons\vppz\library\Vpower::dourl($data['cover_image']);
    }

    public function gettypeList()
    {
        return ['1'=>'社区诊疗','2'=>'居家康养'];
    }
}
